package day081302;


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] strs = new String[n];
        int k =0;
        while(n>0){
            strs[k] = sc.next();
            k++;
            n--;
        }
        String s = String.join(" ",strs);
        countword(strTostrArray(s));
    }
    public static String[] strTostrArray(String str) {
        str = str.toLowerCase();
        String regex="[\\W]+";
        str=str.replaceAll(regex," ");
        String[] strs =str.split(" ");
        return strs;
    }
    public static void countword(String[] strs){
        HashMap<String,Integer> strhash = new HashMap<>();
        Integer in = null;
        for(String s:strs){
            in = strhash.put(s,1);
            if(in!=null){
                strhash.put(s,in+1);
            }
        }
        Set<java.util.Map.Entry<String,Integer>> entrySet = strhash.entrySet();
        String maxStr = null;
        int maxValue=0;
        for(java.util.Map.Entry<String,Integer> e:entrySet){
            String key = e.getKey();
            Integer value = e.getValue();
            if(value>maxValue){
                maxValue=value;
                maxStr=key;
            }

        }
        System.out.println(maxStr+" "+maxValue);
    }
}